<template>
	<view>
		<web-view src="https://zhgw.jingdianqiche.cn/mp3.html?ver=111"></web-view>
	</view>
</template>

<script>
    var plugin = requirePlugin("WechatSI");
    let _this;
    
	export default {
		data() {
			return {
				voice:''
			}
		},
        onReady(e) {
            //创建内部 audio 上下文 InnerAudioContext 对象。
            // this.innerAudioContext = wx.createInnerAudioContext();
            // this.innerAudioContext.onError(function (res) {
            //     console.log(res);
            //     wx.showToast({
            //         title: '语音播放失败',
            //         icon: 'none',
            //     })
            // })
        },
        onLoad() {
            _this = this;
			// let voitimes = uni.getStorageSync('key_partner_voitimes');
			// if(!voitimes){
			// 	voitimes = "10";
			// 	console.log('voitimes不存在，默认为5');
			// }
			// else{
			// 	console.log('voitimes存在，取值'+voitimes);
			// }
			// let vTimes = parseInt(voitimes);
			// let mTimes = vTimes * 1000;
			// setInterval(function(){
			// 	_this.getVoiceList();
			// },mTimes);
        },
		methods: {
            //播放语音
            yuyinPlay: function (e) {
                if (e == '') {
                  console.log(暂无语音);
                  return;
                }
                _this.innerAudioContext.src = 'https://zhgw.jingdianqiche.cn/aaa.mp3'; //设置音频地址
                _this.innerAudioContext.play(); //播放音频
                let tTime;let index = 0;
                tTime = setInterval(function() {
                    console.log('tTime -- ',tTime);
                    index +=1;
                    uni.vibrateLong({
                        fail() {
                            uni.showToast({
                                title: '振动开启失败！'
                            });
                            clearInterval(tTime);
                        }
                    })
                    if (index > 5) {
                       clearInterval(tTime); 
                    }
                }, 1000);
            },
			cbVoiceList:function(resJson){
				console.log('cbVoiceList',resJson);
				if(resJson.data && resJson.data.length > 0){
					plugin.textToSpeech({
					    lang: "zh_CN",
					    tts: true,
					    content: resJson.data,
					    success: function(res) {
					        console.log("succ tts", res.filename)  
					         
					        _this.voice = res.filename;
					        _this.yuyinPlay(res.filename);
					    },
					    fail: function(res) {
					        console.log("fail tts", res)
					    }
					});
				}
			},
            getVoiceList:function(){
			 let openid = uni.getStorageSync('key_partner_openid');
			 _this.$ZcPublic.Server.Post({
			 	IsNeedLogin: false,
			 	Paras: {
			 		Name: 'Uni_Voice',
			 		Action: "getVoiceList",
			 		Data:{
						openid:openid
			 		}
			 	},
			 	Callback:_this.cbVoiceList,
			 	Scope: _this
			 })  
		   },
            // 结束语音
            end: function (e) {
                _this.innerAudioContext.pause();//暂停音频
            }
		}
	}
</script>

<style>

</style>
